package com.example.demo.configuration

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter


/**
 * Created with IntelliJ IDEA.
 * Author:流年的樱花逝
 * Date:2018/11/13
 * Time:14:34
 */
@Configuration
class CustomCorsConfiguration {
    fun buildConfig(): CorsConfiguration {
        val corsConfig = CorsConfiguration()
        corsConfig.addAllowedHeader("*")
        corsConfig.addAllowedOrigin("*")
        corsConfig.addAllowedMethod("*")
        corsConfig.allowCredentials = true
        return corsConfig
    }

    @Bean
    fun corsFilter(): CorsFilter {
        val source = UrlBasedCorsConfigurationSource()
        source.registerCorsConfiguration("/**", buildConfig())
        return CorsFilter(source)
    }



}